// pages/my/welfareTask/welfareTask.js
const {
  myApi
} = require('../../../api/index')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMGBASEURL: app.globalData.IMGBASEURL,
    list: [],
    isMission: false,
    canvas: "",
    time: "",
  },
  itemName(value) {
    console.log("2222", value);
    switch (value.currentTarget.dataset['value']) {
      case 1:
        return "分享小程序"
        break
      case 1:
        return "加入社群"
        break
      case 1:
        return "每日登录小程序"
        break
      case 1:
        return "点赞文章"
        break
    }
  },
  // 点击完成去做任务
  complete(id) {
    if (id.currentTarget.dataset['item'].PreconditionType == 10) { //分享小程序
      let cavas =  wx.getStorageSync('cavas')
      if(cavas){
        this.setData({
          isMission: true,
          canvas: cavas
        })
        return
      }
      const popup = this.selectComponent('#co');
      popup.drawPic()

      let time = setInterval(() => {
        if (wx.getStorageSync('cavas')) {
          this.setData({
            isMission: true,
            canvas: wx.getStorageSync('cavas')
          })
          clearInterval(time)
        } else {

        }

      }, 200)

    } else if (id.currentTarget.dataset['item'].PreconditionType == 7) { //加入社群
      wx.navigateTo({
        url: '../association/association?id=' + id.currentTarget.dataset['item'].ID,

      })
    } else if (id.currentTarget.dataset['item'].PreconditionType == 12) { //登录
      wx.navigateTo({
        url: '../../login/index',
      })
    } else if (id.currentTarget.dataset['item'].PreconditionType == 9) { //点赞文章
      wx.switchTab({
        url: '../../home/index',
      })
    } else if (id.currentTarget.dataset['item'].PreconditionType == 3) { //邀请好友
      wx.navigateTo({
        url: './invitationFriend/index?id='+ id.currentTarget.dataset['item'].ActivityId,
      })
    }
  },

  // 点击描述跳转
  describeRou(index){
    console.log(index.currentTarget);
   if(index.currentTarget.dataset['index'].PreconditionType ==  7){
    wx.navigateTo({
      url: '../association/association',
    })
   }else  if(index.currentTarget.dataset['index'].PreconditionType == 3){
    wx.navigateTo({
      url: './invitationFriend/index?id='+ index.currentTarget.dataset['index'].ActivityId,
    })
   }
  },
  closeComplete() {
    this.setData({
      isMission: false
    })
  },

  // 分享小程序图片
  shareOk() {
    // wx.showShareImageMenu({
    //     path: wx.getStorageSync('cavas'),
    //     success: (res) => {
    //       myApi.shareminiprogramn({}).then((res) => {
    //         console.log(res);
    //         wx.showToast({
    //           title: "分享成功",
    //           icon: "none"
    //         });
    //       })
    //     }
    //   }

    // )

    // wx.showToast({
    //   title: '请点击右上角三个点进行分享',
    //   icon: 'none',
    //   duration: 2000
    // });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  init() {
    myApi.activitylist({
      ActivePort:3,
      AwardList:[1,4]
    }).then(res => {
      this.setData({
        list: res.Result.ActivityInfo
      })
      console.log(res);
    })
  },
  onLoad(options) {
    console.log(111,options.scene);
    this.init()
  },

  onShow() {
    if (this.time) {
      clearTimeout(this.time)
    }
    this.init()
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    let thet = this
    this.time = setTimeout(() => {
      myApi.shareminiprogramn({}).then((res) => {
        thet.init()
        clearTimeout(this.time)
      })
    },500)
    return {
      title: '草图里小程序',
      path: '/pages/home/index',
      imageUrl: '../../../assets/img/logo_11.png',
      success: function (res) {
        // 分享成功的回调  

      }
    }
  }
})